All Questions
Tagged with javaunit-testing
116 questions
4votes
3answers
318views
Clearing static state before testing each method
My SUT class depends on external static state (which generally should be avoided, I know). How do I make sure my tests do not depend on their order of execution? I mean other by introducing some reset(...
0votes
0answers
70views
Is Spring Boot Unit Test Coverage with Integration tests only a bad practice?
I have recently come across a few codebases at work where the previous developers chose to reach the >80% coverage criteria by writing only integration tests with the @SpringBootTest annotation ...
0votes
1answer
124views
Feasibility of using different java version for different project with different compatibility properties
I have multiple Flutter Android app projects that have different compatibilities of Java. Now, what should I do if I am developing more than one project simultaneously? If the first one uses Java 17, ...
0votes
3answers
434views
Would you test this piece of configuration code? How do I determine which code is worth testing?
We have a piece of code that decorates an interface to transparently add retry logic. Inversion of Control configuration service.AddOurRestApiClient() .AddResilienceHandler("Retry", ...
2votes
3answers
264views
Should edge cases be part of one test, or each their own case?
I am writing tests TDD-style for a cryptography package containing encryption and decryption methods. I test my methods with various kinds of inputs, including multiline strings, mixed case, calling ...
2votes
2answers
406views
Should mocks used in unit tests represent entireties or subsets?
I was working on a unit test that has a mock object looking something like: public class TestMock { static { Doodad a = new Doodad(0); Doodad b = new Doodad(1); Doodad c = ...
0votes
1answer
1kviews
Mock a bean with 10 methods when I only use one?
I face some situations similar to the following simplified one: @Component class ServiceOne { @Autowired ServiceTwo two; void act() { ... two.a(); ... } } @...
0votes
1answer
811views
Unit testing parts that use a Value Object that is being created by a Factory
Here is the conundrum, I have a fairly complex Value Object and I don't want to expose it's internals. It should not be an Entity since there is no need for attaching an identity to it. According to ...
36votes
3answers
6kviews
What is the point of repeatedly executing the same test?
I have recently learned about the not-well-known and not-widely-used annotation @RepeatedTest that, as the name implies, repeats the very same test n-times. Baeldung provides a short guide to this ...
1vote
2answers
531views
How to avoid unit test duplication in wrapper classes?
Assuming I’ve a class with three methods, startCollection, add, endCollection. One test case is: if start was not called, add should return an error. I’ve mocked the persistency storing the state with ...
1vote
2answers
342views
Best Practice: Unit test coverage vs. in-method sanity checks [duplicate]
I have a code-coverage requirement of of a certain percentage, and face the following tradeoff: Should I sacrifice in-method sanity checks and error handling for ease of (unit-) testability? Lets ...
0votes
2answers
238views
Is there any benefit testing only with mocks/fakes/doubles?
Say I want to test the behavior of the GUI while I follow a PassiveView approach. I also use the command pattern to handle the actions of the user. So given a PersonView and a PersonService with a ...
5votes
4answers
6kviews
Extending the class to test it: is this testing approach fine?
I am curious if the following example of testing a class with protected methods is fine. For example, say you have the following class Foo that has method a() of return type Bar: class Foo { ...
0votes
2answers
104views
How to cover by tests HTTP API wrapping library
As mentioned in title, I don't understand how I supposed to cover by tests code which is just wrap http api. I guess I can write only unit tests, because wrapped service is paid. Integration tests in ...
0votes
1answer
2kviews
Java: Splitting a large unit test class
The project (Java/Spring) I currently work on has a rather large unit-test class for one of its services : more than 1000 lines, several Nested class (one per big functionality), some tests without a ...